using System;
using System.Collections;
using System.Xml.Serialization;

namespace Slaks.DocumentSerialization.Document
{
	public class Document
	{
		private string m_fileName;
		private long m_totalTermCount;
		private long m_uniqueTermCount;
		private long m_totalSentenceCount;
		private MostFrequencyInfo m_mostFrequencyInfo;

		protected Hashtable m_nodes;

		public Document()
		{
			m_nodes = new Hashtable();
			m_mostFrequencyInfo = new MostFrequencyInfo();
		}
        [XmlElement("original-file_name")]
        public string OriginalFileName { get; set; }

		[XmlElement("file-name")]
		public string FileName
		{
			get { return m_fileName; }
			set { m_fileName = value; }
		}

		[XmlElement("total-term-count")]
		public long TotalTermCount
		{
			get { return m_totalTermCount; }
			set { m_totalTermCount = value; }
		}

		[XmlElement("unique-term-count")]
		public long UniqueTermCount
		{
			get { return m_uniqueTermCount; }
			set { m_uniqueTermCount = value; }
		}

		[XmlElement("total-sentence-count")]
		public long TotalSentenceCount
		{
			get { return m_totalSentenceCount; }
			set { m_totalSentenceCount = value; }
		}

		public MostFrequencyInfo MostFrequencyInfo
		{
			get { return m_mostFrequencyInfo; }
		}

		[XmlArrayItem("node", typeof (Node), IsNullable = true)]
		[XmlArray]
		public ICollection Nodes
		{
			get { return m_nodes.Values; }
		}

	    public Node GetNodeById(long id)
		{
			return (Node) m_nodes[id];
		}

		public void AddNode(long id, Node node)
		{
			m_nodes.Add(id, node);
		}


		/// <summary>
		/// Generate the hashtable which maps string representation (name,term) to Node of this term
		/// </summary>
		/// <returns></returns>
		public Hashtable GenerateString2NodeMap()
		{
			Hashtable string2NodeMap = new Hashtable();

			foreach(Node node in this.Nodes)
			{
				string2NodeMap.Add(node.Term,node);
			}

			return string2NodeMap;
		}

	}
}